package com.etongwl.socketlibrary.library2;

import java.util.concurrent.LinkedBlockingQueue;

/**
 * Created by jason on 16/6/27.
 * 消息队列核心
 */
public class MessageQueueCore<T> {
    //消息队列
    private LinkedBlockingQueue<T> msgQueue;

    public MessageQueueCore(){
        msgQueue=new LinkedBlockingQueue<T>();
    }

    public T getMessage()  {
        try {
            return msgQueue.take();
        } catch (InterruptedException e) {
            e.printStackTrace();
            Thread.currentThread().interrupt();
            return null;
        }
    }

    public void setMessage(T msg) throws InterruptedException {
        msgQueue.put(msg);
    }

    /**
     * 返回队列数量
     * @return
     */
    public int getNum(){
       return msgQueue.size();
    }


}
